package edu.langnan.xiaoli.controller.business;

import edu.langnan.xiaoli.base.AjaxResult;
import edu.langnan.xiaoli.base.controller.BaseController;
import edu.langnan.xiaoli.config.security.TokenService;
import edu.langnan.xiaoli.core.dto.LeaveInfoDTO;
import edu.langnan.xiaoli.core.dto.LeaveParamDTO;
import edu.langnan.xiaoli.service.LeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author cql
 */
@RestController
@RequestMapping("leave")
public class LeaveController extends BaseController {

    @Autowired
    private LeaveService leaveService;

    @Autowired
    private TokenService tokenService;


    @PostMapping
    public AjaxResult insertLeave(@RequestBody LeaveParamDTO param, HttpServletRequest request) {
        Integer stuId = tokenService.getLoginUser(request).getId();
        param.setStuId(stuId);
        leaveService.insertLeave(param);
        return AjaxResult.success();
    }


    @GetMapping("list")
    public AjaxResult leaveList(HttpServletRequest request) {
        Integer stuId = tokenService.getLoginUser(request).getId();
        List<LeaveInfoDTO> result = leaveService.leaveList(stuId);
        return AjaxResult.success(result);
    }

}
